home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / wtek0693.zip / OOPALLEY.ZIP / XCHAT.CPP < prev    next >
C/C++ Source or Header  |  1993-04-27  |  2KB  |  107 lines

  1. #include <stream.h>
  2. #include "display.h"
  3. #include <conio.h>
  4. #include <ctype.h>
  5.  
  6. void printInt(unsigned int i)
  7. {
  8.     cout << "hex: " << hex(i) << "\n";
  9. }
  10.  
  11. void printChat(Chat aChat)
  12. {
  13.     printInt(aChat);  // test cast with operator unsigned()
  14.     cout << "aChat.ch()" << aChat.ch() << "\n";
  15.     cout << "(int)aChat.at()" << aChat.at() << "\n";
  16.     if ( isprint(aChat.ch()) )
  17.         cout << form("implicit cast to %%c: %c\n", aChat);
  18. }
  19.  
  20. main()
  21. {
  22.     cout <<  "hello, world\n";
  23.     Chat noinit;
  24.     Chat A(65);
  25.     Chat a('a');
  26.     Chat b('b', (YELLOW+(BLUE<<4)));
  27.     Chat chatArray[5];
  28.  
  29.     cout << "sizeof(Chat): " << sizeof(Chat) << "\n";
  30.     cout << "sizeof(a): " << sizeof(a) << "\n";
  31.     cout << "sizeof(chatArray): " << sizeof(chatArray) << "\n";
  32.  
  33.     cout << "=====printChat(noinit)=====\n";
  34.     printChat(noinit);
  35.  
  36.     cout << "=====printChat(A)=====\n";
  37.     printChat(A);
  38.  
  39.     cout << "=====printChat(a)=====\n";
  40.     printChat(a);
  41.  
  42.     cout << "=====printChat(b)=====\n";
  43.     printChat(b);
  44.  
  45. #if 1
  46.     noinit=b; // test assignment
  47.     cout << "=====printChat(noinit) noinit=b; =====\n";
  48.     printChat(noinit);
  49.  
  50.     noinit=0xabcd; // test assignment
  51.     cout << "=====printChat(noinit) noinit=0xabcd; =====\n";
  52.     printChat(noinit);
  53. #endif
  54.  
  55.     cout << "=====print chatArray 1=====\n";
  56.     int lim = sizeof(chatArray) / sizeof(Chat);
  57.     for (int i=0; i<lim; i++)
  58.     {
  59.         chatArray[i]=i+(i<<8);
  60.     }
  61.     for (i=0; i<lim; i++)
  62.     {
  63.         cout << i << ": ";
  64.         printChat(chatArray[i]);
  65.     }
  66.  
  67.     cout << "=====print chatArray 2=====\n";
  68.     for (i=0; i<lim; i++)
  69.     {
  70.         chatArray[i]=Chat('a'+i,7+i);
  71.     }
  72.     for (i=0; i<lim; i++)
  73.     {
  74.         cout << i << ": ";
  75.         printChat(chatArray[i]);
  76.     }
  77.  
  78.     cout << "=====print chatArray 3=====\n";
  79.     for (i=0; i<lim; i++)
  80.     {
  81.         chatArray[i].ch('A'+i);
  82.     }
  83.     for (i=0; i<lim; i++)
  84.     {
  85.         cout << i << ": ";
  86.         printChat(chatArray[i]);
  87.     }
  88.  
  89.     cout << "=====print chatArray 4=====\n";
  90.     for (i=0; i<lim; i++)
  91.     {
  92.         chatArray[i].at(0xff);
  93.     }
  94.     for (i=0; i<lim; i++)
  95.     {
  96.         cout << i << ": ";
  97.         printChat(chatArray[i]);
  98.     }
  99.  
  100.     Chat far * pChat = chatArray;
  101.     cout << form("pChat: %lx\n", pChat);
  102.     cout << form("pChat+1: %lx\n", pChat+1);
  103.  
  104.     cout <<  "goodbye, world\n";
  105. }
  106.  
  107.